package com.wtx.chapter07;

import java.util.TreeSet;

/**
 * @description: leetcode 804 唯一的摩斯密码
 * @author: wtx
 * @createDate: 2020/5/26
 */
public class Solution804 {

    public int uniqueMorseRepresentations(String[] words) {

        String[] codes = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
        TreeSet<String> set = new TreeSet<>();
        for (String word: words){

            StringBuilder ret = new StringBuilder();
            for (int i = 0; i < word.length(); i++) {
                ret.append( codes[word.charAt(i) - 'a'] );
            }
            set.add(ret.toString());
        }
        return set.size();
    }
}
